package com.office.meetingManage.meetroom.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.office.meetingManage.meetroom.dao.MeetroomMapper;
import com.office.meetingManage.meetroom.dao.ReservationmeetroomMapper;
import com.office.meetingManage.meetroom.pojo.OaMeetroom;
import com.office.meetingManage.meetroom.pojo.otherPojo.MeetCountExcel;
import com.office.meetingManage.meetroom.service.MeetroomService;
import com.office.meetingManage.meetroom.service.ReservationmeetroomService;
import com.office.onlineInformation.allMessage.pojo.OaOnlineMessage;
import com.office.util.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: 许月
 * @Date: 2022/10/27/11:20
 */
@Service
public class MeetroomServiceImpl implements MeetroomService {
    @Autowired
    private MeetroomMapper meetroomMapper;

    @Autowired
    private ReservationmeetroomService reservationmeetroomService;


    /**
     * 查询列表
     * @param meetroom
     * @param pageModel
     * @return
     */
    @Override
    public PageModel<OaMeetroom> getList(OaMeetroom meetroom, PageModel<OaMeetroom> pageModel) {
        /*System.out.println("***************************************");
        System.out.println(meetroom);
        System.out.println("***************************************");*/

        pageModel.setPageNum(pageModel.getPageNum() <= 0?1: pageModel.getPageNum());
        pageModel.setPageSize(pageModel.getPageSize() <= 0?3: pageModel.getPageSize());

        PageHelper.startPage(pageModel.getPageNum(),pageModel.getPageSize());
        List<OaMeetroom> meetroomList = meetroomMapper.queryList(meetroom);
        System.out.println("获得的列表长度"+meetroomList.size());
        PageInfo<OaMeetroom> pageInfo = new PageInfo<>(meetroomList);
        pageModel.setData(meetroomList);
        pageModel.setTotalPage(pageInfo.getPages());
        pageModel.setTotalRows(pageInfo.getTotal());
        return pageModel;
    }

    /**
     * 通过id查询
     * @param mId
     * @return
     */
    @Override
    public OaMeetroom getBymId(Integer mId) {
        OaMeetroom oaMeetroom = meetroomMapper.queryBymId(mId);
        return oaMeetroom;
    }

    /**
     * 修改会议室
     * @param meetroom
     * @return
     */
    @Override
    public Boolean updateMeetRoom(OaMeetroom meetroom) {

        Integer result = meetroomMapper.updateMeetRoom(meetroom);
        if(result < 1){
            return false;
        }else {
            return true;
        }
    }

    /**
     * 删除会议室
     * @param mId
     * @return
     */
    @Override
    public Boolean deleteMeetRoom(Integer mId) {
        reservationmeetroomService.changeStatus(mId,1);

        Integer result = meetroomMapper.deleteByMid(mId);
        if(result < 1){
            return false;
        }else {
            return true;
        }
    }

    /**
     * 添加会议室操作
     * @param meetroom
     * @return
     */
    @Override
    public Boolean addMeetRoom(OaMeetroom meetroom) {
        Integer result = meetroomMapper.addMeetRoom(meetroom);
        if(result < 1){
            return false;
        }else {
            return true;
        }
    }

    /**
     * 会议报表导出专用
     * @param startMonth 所选月份
     * @param nextMonth
     * @return
     */
    @Override
    public List<MeetCountExcel> findMeetCount(String startMonth, String nextMonth) {
        List<MeetCountExcel> meetCountExcels = meetroomMapper.findMeetCount(startMonth,nextMonth);
        return meetCountExcels;
    }

    /**
     * 判断添加的会议室名称是否重复
     * @param meetRoomName
     * @return
     */
    @Override
    public Boolean findByMeetRoomName(String meetRoomName) {
        List<Integer> mids =  meetroomMapper.findIdByName(meetRoomName);
        if(mids.size() != 0){
            return false;
        }
        return true;
    }

    /**
     * 判断添加的会议室地址是否重复
     * @param meetRoomPlace
     * @return
     */
    @Override
    public Boolean findByMeetRoomPlace(String meetRoomPlace) {
        List<Integer> mids =  meetroomMapper.findIdByPlace(meetRoomPlace);
        if(mids.size()!=0){
            return false;
        }
        return true;
    }

}
